home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / unix / c / close < prev    next >
Text File  |  1996-11-09  |  1KB  |  66 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/close,v $
  4.  * $Date: 1996/10/30 21:59:01 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: close,v $
  10.  * Revision 1.2  1996/10/30 21:59:01  unixlib
  11.  * Massive changes made by Nick Burret and Peter Burwood.
  12.  *
  13.  * Revision 1.1  1996/04/19 21:35:27  simon
  14.  * Initial revision
  15.  *
  16.  ***************************************************************************/
  17.  
  18. static const char rcs_id[] = "$Id: close,v 1.2 1996/10/30 21:59:01 unixlib Rel $";
  19.  
  20. #include <errno.h>
  21. #include <fcntl.h>
  22.  
  23. #include <sys/syslib.h>
  24. #include <sys/types.h>
  25. #include <sys/unix.h>
  26. #include <sys/dev.h>
  27. #include <sys/os.h>
  28. #include <unistd.h>
  29.  
  30. int
  31. close (int fd)
  32. {
  33.   register struct file *f;
  34.  
  35.   if (BADF (fd))
  36.     {
  37.       errno = EBADF;
  38.       return (-1);
  39.     }
  40.  
  41.   f = __u->file + fd;
  42.  
  43.   if (f->dup != f)
  44.     {
  45.       register struct file *_f;
  46.  
  47.       _f = f->dup;
  48.       while (_f->dup != f)
  49.     {
  50.       _f = _f->dup;
  51.     }
  52.  
  53.       _f->dup = f->dup;
  54.     }
  55.   else
  56.     {
  57.       if (f->pid == __u->pid)
  58.     if (__funcall ((*(__dev[major (f->dev)].close)), (minor (f->dev), f)) < 0)
  59.       return (-1);
  60.     }
  61.  
  62.   f->dup = 0;
  63.  
  64.   return (0);
  65. }
  66.